#include<stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
#include<string.h>

const char *str = "i like linux";
char arr[100];
int size=0;

int main()
{
    int arr[2]={0};
    int getpipe=pipe(arr);
    if(getpipe==-1)
    {
        perror("pipe :");
    }


    pid_t id=fork();

    if(id==0)
    {
        int cout=0;
        close(arr[1]);
        while(1)
        {
            char buff[1024];
            int size=read(arr[0],buff,8);
            buff[size]=0;
            printf("%s",buff);
            printf(" %d\n",cout++);
        }
    }
    else 
    {
        int count=1;
        close(arr[0]);
        while(1)
        {
            char str[8];
            sprintf(str,"zgwnbb %d",count++);
            write(arr[1],str,8);
            sleep(1);
        }
    }
    return 0;
}
